import {
    PACKUP,
    MAJORMAP1,
    MAJORMAP0,
    CLEARALL,
    OPENRALL,
    UPDATED,
    OPENAIRLINE,
    RETRUNROUTE
} from './types'
import getters from './getters'
import {state} from './state.js'
const mutations = {
    [MAJORMAP0](state) {
        if(state.mapData.bmap.zoom>5){
            state.mapData.bmap.zoom--;
            state.mapData=JSON.parse(JSON.stringify(state.mapData));
        }
    },
    [MAJORMAP1](state) {
        if(state.mapData.bmap.zoom<7){
            state.mapData.bmap.zoom++;
            state.mapData=JSON.parse(JSON.stringify(state.mapData));
        }
    },
    [CLEARALL](state) {
        state.nested_page=false;
    },
    [OPENRALL](state) {
        state.nested_page=true;
    },
    [UPDATED](state) {
        state.c_updated=!state.c_updated;
    },
    [RETRUNROUTE](state) {
        state.mapState=0;
        state.mapData=state.mapDataOld;
        $('#searchWrap').hide();
        $('.acc_diagram').show();
    },
    [OPENAIRLINE](state) {
        let flag = false;
        if(!!window.localStorage.getItem('ChinaLines')){
            flag = true;
        }
        if(flag){
            state.mapData = JSON.parse(window.localStorage.getItem('ChinaLines'));
            $('.acc_diagram').hide();
        }else{
            //
        }
        //start  in else
        $.ajax({
            url:"restful/getChinaAirLineData",
            dataType:'jsonp',
            type:"get",
            data:{},
            success:(data)=> {
                var Collection={
                    "bmap":{"center":["110.47","32.40"],"zoom":6,"color":"red","roam":"move","mapStyle":{"styleJson":[{"featureType":"water","elementType":"all","stylers":{"color":"#071327","visibility":"on"}},{"featureType":"land","elementType":"all","stylers":{"color":"#223350","visibility":"on"}},{"featureType":"boundary","elementType":"all","stylers":{"color":"#465b6c","visibility":"on"}},{"featureType":"arterial","elementType":"all","stylers":{"visibility":"off"}},{"featureType":"highway","elementType":"all","stylers":{"visibility":"off"}},{"featureType":"label","elementType":"all","stylers":{"visibility":"off"}}]}},
                    "tooltip":{
                        "trigger": "item",
                        "show": false,
                    },
                    "series":[
                        {
                            "name":"全国航线",
                            "coordinateSystem":"bmap",
                            "type":"lines",
                            "zlevel":0,
                            "lineStyle":{
                                "normal":{
                                    "color":"#4088B6",
                                    "width":"0.5",
                                    "opacity":0.4,
                                    "curveness":0.2},
                                "emphasis":{"color":"#3887be"}
                            },
                            "polyline":false,
                            "data":data.success.chinaAriLineDataList,
                            "blendMode":"lighter",
                        },
                        {
                            "name": "全国重点机场",
                            "coordinateSystem":"bmap",
                            "type":"scatter",
                            "label": {
                                "normal": {
                                    formatter: '{b}',
                                    position: 'right',
                                    show: true,
                                    textStyle:{
                                        color:"white"
                                    }
                                }
                            },
                            "itemStyle": {
                                "normal": {
                                    color: '#eaf4ff',
                                    shadowBlur: 10,
                                    shadowColor: '#333'
                                }
                            },
                            "data":[{"name":"北京","value":["116.24", "39.55",0]},{"name":"上海","value":["121.29", "31.14",0]},{"name":"深圳","value":["114.07", "22.33",0]},{"name":"广州","value":["113.14", "23.08",0]},{"name":"昆明","value":["102.42", "25.04",0]},{"name":"成都","value":["104.04","30.40",0]},{"name":"杭州","value":["120.10","30.16",0]},{"name":"武汉","value":["114.17","30.35",0]},{"name":"重庆","value":["106.33","29.35",0]},{"name":"南京","value":["118.46","32.03",0]},{"name":"天津","value":["117.12","39.02",0]},{"name":"西安","value":["108.57","34.17",0]},{"name":"长沙","value":["112.59","28.12",0]},{"name":"沈阳","value":["123.25","41.48",0]},{"name":"青岛","value":["120.18","36.03",0]},{"name":"郑州","value":["113.40","34.46",0]},{"name":"大连","value":["121.36","38.55",0]},{"name":"宁波","value":["121.33","29.52",0]}]
                        },
                        {
                            "type": "scatter",
                            "coordinateSystem": "bmap",
                            "data": state.mapData.series[1].data,
                            "zlevel": 10,
                            "symbolSize": [15, 20],
                            "symbol": "path://M786.496 161.163l-3.537-3.507C713.308 88.89 617.627 46.381 511.992 46.381c-105.507 0-201.123 42.418-270.76 111.073l-3.926 3.911c-68.646 69.668-111.074 165.237-111.074 270.775 0 105.633 42.495 201.295 111.275 270.965l3.522 3.508 270.978 271.006 271.169-271.146 3.132-3.164c68.889-69.697 111.459-165.424 111.459-271.164C897.772 326.521 855.277 230.86 786.496 161.163L786.496 161.163zM512.008 541.766c-74.545 0-134.974-60.447-134.974-134.977 0-30.806 10.283-59.152 27.614-81.856 24.663-32.299 63.574-53.151 107.359-53.151 74.55 0 134.978 60.463 134.978 135.008C646.985 481.318 586.558 541.766 512.008 541.766L512.008 541.766zM512.008 541.766",
                            "symbolOffset": [0, -8],
                            "itemStyle": {
                                "emphasis": {},
                                "normal": {
                                    "color": "#d85230"
                                }
                            }
                        },
                    ]
                };
                data.success.chinaAriLineDataList.forEach(function(value){
                    value.coords=[value.coords.fromName,value.coords.toName];
                });
                state.mapAllline=JSON.parse(JSON.stringify(Collection));
                window.localStorage.setItem('ChinaLines',JSON.stringify(Collection));
                state.mapData=state.mapAllline;
                $('.acc_diagram').hide();
            }
        });
        //  end
        state.mapState=1;
    }
};

export default {
	state,
	mutations,
	getters
}